<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>

    // 异步操作 => 未来改变状态
    var p = new Promise(function (resolve, reject) {

        aaa; // {rejected:err}

        // setTimeout(function () {
        //     var num = Math.random(); // 0-1
        //     console.log(num);
        //     if (num < 0.5) {
        //         resolve("正面");
        //     } else {
        //         reject("反面"); // {rejected:"反面"}
        //     }
        // }, 2000);
    })

    console.log("页面加载:", p); // {pending:undefined}

    p.then(function (res) {
        console.log("fulfilled", res);
    }, function (res) {
        console.log("rejected", res);
    })

</script>

</html>